package cn.bearspark.common.assess;

import java.time.Duration;

/**
 * 针对 有时间和浏览量的评估数据 的评估器
 *
 * @author f
 */
public class TimedViewedDataAssessor implements Assessor<TimedViewedData> {

    /**
     * 时间因子，介于 0~1 之间
     */
    private final float timeFactor;

    /**
     * 浏览量因子，介于 0~1 之间
     */
    private final float viewFactor;

    public TimedViewedDataAssessor(float timeFactor) {
        if (!(0 <= timeFactor && timeFactor <= 1)) {
            throw new IllegalArgumentException("time factor must be between 0 and 1");
        }
        this.timeFactor = timeFactor;
        this.viewFactor = 1.0f - timeFactor;
    }

    @Override
    public double calScore(TimedViewedData data) {
        // TODO 实现一个比较好的计算分数的算法
        return data.getViewNum() / 1000.0 * viewFactor +
               Duration.between(AssessedData.ORIGIN_TIME, data.getCreateTime()).toMinutes() / 100.0 * timeFactor;
    }
}
